home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Bitmap Libraries 2.0 / 411 files / BitMapHelp next >
Text File  |  1996-03-10  |  41KB  |  1,335 lines

  1. æKY CopyrightNoticeBitMapHelp
  2. æC -----
  3.     BitMapHelp Copyright (c) 1996 by John Montbriand.  All rights reserved.
  4.  
  5. æKY BitMap.h
  6. BitMapHelp
  7. BitMaps
  8. æC -----
  9. Routines for working with bitmap pointers. 
  10. BitMapHelp Copyright (c) 1996 by John Montbriand.  All rights reserved.
  11.  
  12. storage managment for bitmaps:
  13.     NewBitMap           -- create a new bitmap pointer                        
  14.     KillBitMap          -- dispose of a bitmap pointer                 
  15.     DuplicateBitMap     -- make a duplicate
  16.     
  17. flip and rotate routines:
  18.     RotateRight         -- 90 degrees to the right
  19.     RotateLeft          -- 90 degrees to the left
  20.     FlipVertical        -- flip vertically
  21.     FlipHorizontal      -- flip horizontally
  22.     RotateBitMap        -- rotate to a particular angle
  23.     
  24. paint bucket and lasso routines:
  25.     PaintBucketBitMap   -- paint bucket
  26.     LassoBitMap         -- the lasso
  27.  
  28. special effects:
  29.     TraceBitMap         -- trace the edges of a bitmap image
  30.  
  31. QuickDraw picture transfer functions:
  32.     PICTToBitMap        -- convert a QuicDraw Picture to a bitmap pointer
  33.     BitMapToPICT        -- convert a bitmap pointer to a QuicDraw Picture
  34.  
  35. logical operations:
  36.     BitMapAND           -- logically AND raster data
  37.     BitMapOR            -- logically OR raster data
  38.     BitMapXOR           -- logically XOR raster data
  39.     BitMapNOT           -- logically COMPLEMENT raster data
  40.  
  41. comparison:
  42.     EqualBitMaps        -- compare two bitmaps for equality
  43.  
  44. pixel oriented functions:
  45.     BitMapTest          -- test the value of a particular pixel
  46.     BitMapSet           -- set a particular pixel to the value 1
  47.     BitMapClear         -- set a particular pixel to the value 0
  48.     BitMapToggle        -- invert a pixel returning it's new value
  49.  
  50. routines for drawing into bitmaps:
  51.     NewBMP              -- called by WithBitMap to set up a grafport
  52.     DisposeBMP          -- called by WithBitMap to dispose of a grafport
  53.     WithBitMap          -- MACRO for drawing into bitmaps
  54.  
  55. routines for copying bitmap data:
  56.     PlotBitMap          -- copy bitmap data to the current grafport
  57.     
  58.  
  59. æKY NewBitMap
  60. æFc BitMap.h
  61. æMM
  62. æD BitMap* NewBitMap(short width, short height);
  63. æDT BitMap *bits = NewBitMap((short) width, (short) height);
  64. æT Function
  65. æC -----
  66. for creating a new bitmap pointer. 
  67.     
  68.     arguments:
  69.         width     the width of the requested bitmap
  70.         height    the height of the requested bitmap
  71.     
  72.     return value:
  73.         a pointer to a Bitmap data structure. 
  74.         if an error occurs, NULL is returned.
  75.         
  76.     description:
  77.         NewBitMap creates a new bitmap pointer with the requested
  78.         dimensions.  The raster data is initialized to zeros, and if
  79.         there is not enough memory to allocate the bitmap, NewBitMap
  80.         will return NULL.
  81.         
  82.     example application:
  83.         The following creates a new bitmap pointer 100 pixels wide
  84.         and 200 pixels tall.
  85.         
  86.         {   BitMap *the_bits;
  87.             
  88.             the_bits = NewBitMap(100, 200);
  89.             ...
  90.             
  91.     notes:
  92.         You can call DisposePtr to dispose of a bitmap pointer created by
  93.         NewBitMap.  The routine KillBitMap calls DisposePtr.
  94.  
  95.  
  96. æKY KillBitMap
  97. æFc BitMap.h
  98. æMM
  99. æD void KillBitMap(BitMap* bits);
  100. æDT KillBitMap((BitMap*) bits);
  101. æT Procedure
  102. æC -----
  103. to dispose of the storage occupied by a bitmap pointer. 
  104.     
  105.     arguments:
  106.         bits    a bitmap pointer
  107.     
  108.     return value:
  109.         none.
  110.         
  111.     description:
  112.         KillBitMap disposes of a bitmap pointer allocated by one of:
  113.         
  114.         NewMacPaintBitMap, NewBitMap, RotateRight, RotateLeft, FlipVertical,
  115.         FlipHorizontal, RotateBitMap, DuplicateBitMap, PaintBucketBitMap,
  116.         LassoBitMap, PICTToBitMap, BitMapAND, BitMapOR, BitMapXOR, or BitMapNOT.
  117.         
  118.         It's your general all purpose bitmap pointer disposal function.
  119.  
  120.     example application:
  121.         The following creates a new bitmap handle 100 pixels wide
  122.         and 200 pixels tall and then disposes of it by calling KillBitMap.
  123.         
  124.         {   BitMap *the_bits;
  125.             
  126.             the_bits = NewBitMap(100, 200);
  127.             if (the_bits != NULL) {
  128.             
  129.                 KillBitMap(the_bits);
  130.             }
  131.             
  132.     notes:
  133.         KillBitMap simply calls DisposePtr.
  134.  
  135.  
  136. æKY RotateRight
  137. æFc BitMap.h
  138. æMM
  139. æD BitMap* RotateRight(BitMap* bits);
  140. æDT BitMap *round_bits = RotateRight((BitMap*) bits);
  141. æT Function
  142. æC -----
  143. to rotate a bitmap 90 degrees to the right. 
  144.     
  145.     arguments:
  146.         bits    a bitmap pointer
  147.     
  148.     return value:
  149.         a newly created bitmap pointer containing the image
  150.         from the bitmap pointer parameter rotated 90 degrees
  151.         to the right. 
  152.         if an error occurs, RotateRight will return the value NULL.
  153.         
  154.     description:
  155.         RotateRight creates a new bitmap containing the image
  156.         stored in the parameter bitmap pointer rotated 90 degrees
  157.         to the right.  The resulting bitmap is appropriately sized:
  158.         i.e. if the source bitmap is 100 pixels wide and 200 pixels tall,
  159.         then the result bitmap pointer will be 200 pixels wide and 100
  160.         pixels tall.  
  161.  
  162.     example application:
  163.         The example creates a new bitmap pointer containing the image
  164.         stored in the original bitmap rotated 90 degrees to the right
  165.         before copying the image to the current grafport.
  166.         
  167.         {   BitMap *the_bits;
  168.             BitMap *rotated_bits;
  169.             Rect bounds;
  170.             
  171.             the_bits = NewBitMap(100, 200);
  172.             if (the_bits != NULL) {
  173.             
  174.                 /* here we would draw something into the_bits */
  175.                 
  176.                 rotated_bits = RotateRight(the_bits);
  177.                 
  178.                 if (rotated_bits != NULL) {
  179.                     bounds = (*rotated_bits)->bounds;
  180.                     PlotMap(rotated_bits, 0, 0, srcCopy);
  181.                     KillBitMap(rotated_bits);
  182.                 }
  183.  
  184.                 KillBitMap(the_bits);
  185.             }
  186.             
  187.     notes:
  188.         RotateRight takes advantage of certain addressing and indexing
  189.         possibilities offered by the arrangement of the raster data
  190.         in memory.  It is faster than calling RotateBitMap and specifying
  191.         a 90 degree angle.
  192.  
  193.  
  194. æKY RotateLeft
  195. æFc BitMap.h
  196. æMM
  197. æD BitMap* RotateLeft(BitMap* bits);
  198. æDT BitMap *left_bits = RotateLeft((BitMap*) bits);
  199. æT Function
  200. æC -----
  201. to rotate a bitmap image 90 degrees to the left. 
  202.     
  203.     arguments:
  204.         bits    a bitmap pointer
  205.     
  206.     return value:
  207.         a newly created bitmap pointer containing the image
  208.         from the bitmap pointer parameter rotated 90 degrees
  209.         to the left. 
  210.         if an error occurs, RotateLeft will return the value NULL.
  211.         
  212.     description:
  213.         RotateLeft creates a new bitmap containing the image
  214.         stored in the parameter bitmap pointer rotated 90 degrees
  215.         to the left.  The resulting bitmap is appropriately sized:
  216.         i.e. if the source bitmap is 100 pixels wide and 200 pixels tall,
  217.         then the result bitmap pointer will be 200 pixels wide and 100
  218.         pixels tall.  
  219.  
  220.     example application:
  221.         The example creates a new bitmap pointer containing the image
  222.         stored in the original bitmap rotated 90 degrees to the left
  223.         before copying the image to the current grafport.
  224.         
  225.         {   BitMap *the_bits;
  226.             BitMap *rotated_bits;
  227.             Rect bounds;
  228.             
  229.             the_bits = NewBitMap(100, 200);
  230.             if (the_bits != NULL) {
  231.             
  232.                 /* here we would draw something into the_bits */
  233.                 
  234.                 rotated_bits = RotateLeft(the_bits);
  235.                 
  236.                 if (rotated_bits != NULL) {
  237.                     bounds = (*rotated_bits)->bounds;
  238.                     PlotMap(rotated_bits, 0, 0, srcCopy);
  239.                     KillBitMap(rotated_bits);
  240.                 }
  241.  
  242.                 KillBitMap(the_bits);
  243.             }
  244.             
  245.     notes:
  246.         RotateLeft takes advantage of certain addressing and indexing
  247.         possibilities offered by the arrangement of the raster data
  248.         in memory.  It is faster than calling RotateBitMap and specifying
  249.         a -90 degree angle.
  250.  
  251.  
  252. æKY FlipVertical
  253. æFc BitMap.h
  254. æMM
  255. æD BitMap* FlipVertical(BitMap* bits);
  256. æDT BitMap *vertical_bits = FlipVertical((BitMap*) bits);
  257. æT Function
  258. æC -----
  259. to flip a bitmap vertically. 
  260.     
  261.     arguments:
  262.         bits    a bitmap pointer
  263.     
  264.     return value:
  265.         a newly created bitmap pointer containing the image
  266.         from the bitmap pointer parameter flipped upside down. 
  267.         if an error occurs, FlipVertical will return the value NULL.
  268.         
  269.     description:
  270.         FlipVertical creates a new bitmap containing the image
  271.         stored in the parameter bitmap pointer flipped upside
  272.         down.  The resulting bitmap will be the same size as
  273.         the original image.  
  274.  
  275.     example application:
  276.         The example creates a new bitmap pointer containing the image
  277.         stored in the original bitmap flipped upside down before
  278.         copying the new flipped image to the current grafport.
  279.         
  280.         {   BitMap *the_bits;
  281.             BitMap *flippin_bits;
  282.             Rect bounds;
  283.             
  284.             the_bits = NewBitMap(100, 200);
  285.             if (the_bits != NULL) {
  286.             
  287.                 /* here we would draw something into the_bits */
  288.                 
  289.                 flippin_bits = FlipVertical(the_bits);
  290.                 
  291.                 if (flippin_bits != NULL) {
  292.                     bounds = (*flippin_bits)->bounds;
  293.                     PlotMap(flippin_bits, 0, 0, srcCopy);
  294.                     KillBitMap(flippin_bits);
  295.                 }
  296.  
  297.                 KillBitMap(the_bits);
  298.             }
  299.             
  300.     notes:
  301.         flippin!
  302.  
  303.  
  304. æKY FlipHorizontal
  305. æFc BitMap.h
  306. æMM
  307. æD BitMap* FlipHorizontal(BitMap* bits);
  308. æDT BitMap *horizontal_bits = FlipHorizontal((BitMap*) bits);
  309. æT Function
  310. æC -----
  311. to flip a bitmap horizontally. 
  312.     
  313.     arguments:
  314.         bits    a bitmap pointer
  315.     
  316.     return value:
  317.         a newly created bitmap pointer containing the image
  318.         from the bitmap pointer parameter flipped horizontally. 
  319.         if an error occurs, FlipVertical will return the value NULL.
  320.         
  321.     description:
  322.         FlipHorizontal creates a new bitmap containing the image
  323.         stored in the parameter bitmap pointer flipped horizontally.
  324.         The resulting bitmap will be the same size as the original image.  
  325.  
  326.     example application:
  327.         The example creates a new bitmap pointer containing the image
  328.         stored in the original bitmap flipped horizontally before
  329.         copying the new flipped image to the current grafport.
  330.         
  331.         {   BitMap *the_bits;
  332.             BitMap *flippin_bits;
  333.             Rect bounds;
  334.             
  335.             the_bits = NewBitMap(100, 200);
  336.             if (the_bits != NULL) {
  337.             
  338.                 /* here we would draw something into the_bits */
  339.                 
  340.                 flippin_bits = FlipHorizontal(the_bits);
  341.                 
  342.                 if (flippin_bits != NULL) {
  343.                     bounds = (*flippin_bits)->bounds;
  344.                     PlotMap(flippin_bits, 0, 0, srcCopy);
  345.                     KillBitMap(flippin_bits);
  346.                 }
  347.  
  348.                 KillBitMap(the_bits);
  349.             }
  350.             
  351.     notes:
  352.         none.
  353.  
  354.  
  355. æKY RotateBitMap
  356. æFc BitMap.h
  357. æMM
  358. æD BitMap* RotateBitMap(BitMap* bits, short cx, short cy, float angle);
  359. æDT BitMap *round_bits = RotateBitMap((BitMap*) bits, (short) cx, (short) cy, (float) angle);
  360. æT Function
  361. æC -----
  362. to rotate a bitmap to a specific angle. 
  363.     
  364.     arguments:
  365.         bits      a bitmap pointer
  366.         cx        the horizontal center of rotation
  367.         cy        the vertical center of rotation
  368.         angle     the angle (in degrees) to rotate the image. both positive
  369.                   and negative values are ok.  This is a floating point number.
  370.                 
  371.     return value:
  372.         a newly created bitmap pointer containing the image
  373.         from the bitmap pointer parameter rotated around the center
  374.         cx and cy angle degrees. 
  375.         if an error occurs, RotateBitMap will return the value NULL.
  376.         
  377.     description:
  378.         RotateBitMap creates a new bitmap containing the image from
  379.         the parameter bitmap pointer rotated angle degrees about the
  380.         center (cx, cy).  The resultant bitmap will have the same dimensions
  381.         as the parameter bitmap regardless of the angle specified.
  382.  
  383.     example application:
  384.         The example creates a new bitmap pointer containing the image
  385.         stored in the original bitmap rotated 35.5 degrees to the right
  386.         before copying the rotated image to the current grafport.
  387.         
  388.         {   BitMap *the_bits;
  389.             BitMap *round_bits;
  390.             Rect bounds;
  391.             
  392.             the_bits = NewBitMap(100, 200);
  393.             if (the_bits != NULL) {
  394.             
  395.                 /* here we would draw something into the_bits */
  396.                 
  397.                 round_bits = RotateBitMap(the_bits, 50, 100, 35.5);
  398.                 
  399.                 if (round_bits != NULL) {
  400.                     bounds = (*round_bits)->bounds;
  401.                     PlotMap(round_bits, 0, 0, srcCopy);
  402.                     KillBitMap(round_bits);
  403.                 }
  404.  
  405.                 KillBitMap(the_bits);
  406.             }
  407.             
  408.     notes:
  409.         The 68k implementation of RotateBitMap has a speedy implementation
  410.         built on top of the fixed math routines.  For more information
  411.         about fixed math refer to the Mathematical and Logical Utilities
  412.         chapter of Inside Macintosh: Operating System Utilities.
  413.  
  414.  
  415. æKY DuplicateBitMap
  416. æFc BitMap.h
  417. æMM
  418. æD BitMap* DuplicateBitMap(BitMap* bits);
  419. æDT BitMap *bitmap_copy = DuplicateBitMap((BitMap*) bits);
  420. æT Function
  421. æC -----
  422. to make a copy of a bitmap. 
  423.     
  424.     arguments:
  425.         bits    a bitmap pointer
  426.     
  427.     return value:
  428.         a newly created bitmap pointer containing an
  429.         exact duplicate of the bitmap parameter.
  430.         if an error occurs, DuplicateBitMap will return the value NULL.
  431.         
  432.     description:
  433.         DuplicateBitMap creates a copy of the bitmap parameter.
  434.  
  435.     example application:
  436.         In this example, we make a new bitmap, duplicate it, and then
  437.         dispose of the resulting bitmaps.
  438.         
  439.         {   BitMap *the_bits;
  440.             BitMap *other_bits;
  441.             
  442.             the_bits = NewBitMap(100, 200);
  443.             if (the_bits != NULL) {
  444.             
  445.                 other_bits = DuplicateBitMap(the_bits); 
  446.                 if (other_bits != NULL) {
  447.                 
  448.                     KillBitMap(other_bits);
  449.                 }
  450.                 
  451.                 KillBitMap(the_bits);
  452.             }
  453.             
  454.     notes:
  455.         none.
  456.  
  457.  
  458. æKY PaintBucketBitMap
  459. æFc BitMap.h
  460. æMM
  461. æD BitMap* PaintBucketBitMap(BitMap* bits, short h, short v);
  462. æDT BitMap *painted_bits = PaintBucketBitMap((BitMap*) bits, (short) h, (short) v);
  463. æT Function
  464. æC -----
  465. to create a paint bucket type mask for a bitmap. 
  466.     
  467.     arguments:
  468.         bits     a bitmap pointer
  469.         h        the horizontal position to start painting
  470.         v        the vertical position to start painting
  471.     
  472.     return value:
  473.         a newly created bitmap pointer containing an ones in every
  474.         pixel where paint would not leak out starting from the point
  475.         (h, v).
  476.         if an error occurs, PaintBucketBitMap will return the value NULL.
  477.         
  478.     description:
  479.         PaintBucketBitMap works like the paint bucket tool found in
  480.         most graphical applications.  It calls the routine SeedFill
  481.         and to fill in the image information in the resulting bitmap
  482.         pointer.
  483.  
  484.     example application:
  485.         In this example, we make a new bitmap and create a mask bitmap
  486.         using the PaintBucketBitMap routine starting at the point (50,50).
  487.         
  488.         {   BitMap *the_bits;
  489.             BitMap *paint_bits;
  490.             
  491.             the_bits = NewBitMap(100, 200);
  492.             if (the_bits != NULL) {
  493.             
  494.                 /* here, we would normally draw something in the bitmap */
  495.                 
  496.                 paint_bits = PaintBucketBitMap(the_bits, 50, 50); 
  497.                 
  498.                 if (paint_bits != NULL) {
  499.                 
  500.                     KillBitMap(paint_bits);
  501.                 }
  502.                 
  503.                 KillBitMap(the_bits);
  504.             }
  505.             
  506.     notes:
  507.         PaintBucketBitMap calls SeedFill.  For further information about
  508.         SeedFill refer to page 3-109 in the QuickDraw Drawing chapter of
  509.         Inside Macintosh: Imaging With QuickDraw.
  510.  
  511.  
  512. æKY LassoBitMap
  513. æFc BitMap.h
  514. æMM
  515. æD BitMap* LassoBitMap(BitMap* bits);
  516. æDT BitMap *lassod_bits = LassoBitMap((BitMap*) bits);
  517. æT Function
  518. æC -----
  519. to create a lasso'd mask of a bitmap. 
  520.     
  521.     arguments:
  522.         bits    a bitmap pointer
  523.     
  524.     return value:
  525.         a newly created bitmap pointer containing an ones in every
  526.         pixel where paint would not leak in from the edges of the
  527.         bitmap.
  528.         if an error occurs, LassoBitMap will return the value NULL.
  529.         
  530.     description:
  531.         LassoBitMap works like the lasso bucket tool found in
  532.         most graphical applications.  It calls the routine CalcMask
  533.         and to fill in the image information in the resulting bitmap
  534.         pointer.
  535.  
  536.     example application:
  537.         In this example, we make a new bitmap and create a mask bitmap
  538.         using the LassoBitMap routine.
  539.         
  540.         {   BitMap *the_bits;
  541.             BitMap *paint_bits;
  542.             
  543.             the_bits = NewBitMap(100, 200);
  544.             if (the_bits != NULL) {
  545.             
  546.                 /* here, we would normally draw something in the bitmap */
  547.                 
  548.                 paint_bits = LassoBitMap(the_bits); 
  549.                 
  550.                 if (paint_bits != NULL) {
  551.                 
  552.                     KillBitMap(paint_bits);
  553.                 }
  554.                 
  555.                 KillBitMap(the_bits);
  556.             }
  557.             
  558.     notes:
  559.         LassoBitMap calls CalcMask.  For further information about
  560.         CalcMask refer to page 3-111 in the QuickDraw Drawing chapter of
  561.         Inside Macintosh: Imaging With QuickDraw.
  562.  
  563.  
  564. æKY TraceBitMap
  565. æFc BitMap.h
  566. æMM
  567. æD BitMap* TraceBitMap(BitMap* bits);
  568. æDT BitMap *traced_bits = TraceBitMap((BitMap*) bits);
  569. æT Function
  570. æC -----
  571. to create a traced edges version of the bitmap. 
  572.     
  573.     arguments:
  574.         bits    a bitmap pointer
  575.     
  576.     return value:
  577.         a newly created bitmap pointer containing containing the original
  578.         image with the edges traced.
  579.         if an error occurs, TraceBitMap will return the value NULL.
  580.         
  581.     description:
  582.         TraceBitMap performs the 'trace edges' command found in
  583.         many graphical applications returning a new bitmap
  584.         containing the traced image..
  585.  
  586.     example application:
  587.         In this example, we make a new bitmap and create a new bitmap
  588.         containing the traced image.
  589.         
  590.         {   BitMap *the_bits;
  591.             BitMap *traced_bits;
  592.             
  593.             the_bits = NewBitMap(100, 200);
  594.             if (the_bits != NULL) {
  595.             
  596.                 /* here, we would normally draw something in the bitmap */
  597.                 
  598.                 traced_bits = TraceBitMap(the_bits); 
  599.                 
  600.                 if (traced_bits != NULL) {
  601.                 
  602.                     KillBitMap(traced_bits);
  603.                 }
  604.                 
  605.                 KillBitMap(the_bits);
  606.             }
  607.             
  608.     notes:
  609.         none.
  610.  
  611.  
  612. æKY EqualBitMaps
  613. æFc BitMap.h
  614. æMM
  615. æD Boolean EqualBitMaps(BitMap* a, BitMap* b);
  616. æDT Boolean is_equal = EqualBitMaps((BitMap*) a, (BitMap*) b);
  617. æT Function
  618. æC -----
  619. compares two bitmaps for equality. 
  620.     
  621.     arguments:
  622.         a    a bitmap pointer
  623.         b    a bitmap pointer
  624.     
  625.     return value:
  626.         true or false.
  627.         
  628.     description:
  629.         returns true if the two bitmaps are the same size and
  630.         contain the same image content.  returns false if either
  631.         bitmap is NULL.
  632.  
  633.     example application:
  634.         In this example, we make a new bitmap and create a two bitmaps
  635.         and compare them by calling EqualBitMaps.
  636.         
  637.         {   BitMap *the_bits;
  638.             BitMap *other_bits;
  639.             
  640.             the_bits = NewBitMap(100, 200);
  641.             if (the_bits != NULL) {
  642.             
  643.                 other_bits = TraceBitMap(the_bits); 
  644.                     
  645.                 if (other_bits != NULL) {
  646.                     
  647.                     /* here, we would normally draw something in the bitmaps */
  648.                     
  649.                     if (EqualBitMaps(other_bits, the_bits)) {
  650.                     
  651.                         /* they're the same *blink* */
  652.                         
  653.                     }
  654.                     
  655.                     KillBitMap(other_bits);
  656.                 }
  657.                 KillBitMap(the_bits);
  658.             }
  659.             
  660.     notes:
  661.         EqualBitMaps takes into account that either bitmap may have
  662.         different rowBytes values, and the possibility that garbage
  663.         values may be stored in the unused bits off to the right
  664.         of the boundary rectangle.
  665.  
  666.  
  667. æKY PICTToBitMap
  668. æFc BitMap.h
  669. æMM
  670. æD BitMap* PICTToBitMap(PicHandle pic);
  671. æDT BitMap *picture_bits = PICTToBitMap((PicHandle) pic);
  672. æT Function
  673. æC -----
  674. to convert a QuickDraw Picture into a bitmap pointer. 
  675.     
  676.     arguments:
  677.         pic        a handle to a QuickDraw picture
  678.     
  679.     return value:
  680.         a newly created bitmap pointer containing a black and white
  681.         representation of the image drawn by the quickdraw picture
  682.         parameter.
  683.         if an error occurs, PICTToBitMap will return the value NULL.
  684.         
  685.     description:
  686.         PICTToBitMap creates a new bitmap pointer the using the size
  687.         information provided in the QuickDraw picture handle parameter
  688.         and draws the picture in the bitmap before returning the bitmap.
  689.  
  690.     example application:
  691.         In this example, we call GetPicture to retrieve a picture from
  692.         a resource file and then we convert it to a bitmap by calling
  693.         the routine PICTToBitMap.
  694.         
  695.         {   PicHandle the_picture;
  696.             BitMap *the_bits;
  697.             
  698.             the_picture = GetPicture(128);
  699.             if (the_picture != NULL) {
  700.             
  701.                 the_bits = PICTToBitMap(the_picture);
  702.                 
  703.                 if (the_bits != NULL) {
  704.                     
  705.                     /* at this point, the the_bits contains the picture */
  706.                     
  707.                     KillBitMap(the_bits);
  708.                 }
  709.             
  710.             }
  711.             
  712.     notes:
  713.         none.
  714.  
  715.  
  716. æKY BitMapToPICT
  717. æFc BitMap.h
  718. æMM
  719. æD PicHandle BitMapToPICT(BitMap* bits);
  720. æDT PicHandle the_picture = BitMapToPICT((BitMap*) bits);
  721. æT Function
  722. æC -----
  723. to convert a bitmap pointer into a QuickDraw Picture. 
  724.     
  725.     arguments:
  726.         bits    a bitmap pointer
  727.     
  728.     return value:
  729.         a handle to a QuickDraw picture. 
  730.         if an error occurs, the picture's picFrame will be
  731.         an empty rectangle.
  732.         
  733.     description:
  734.         BitMapToPICT returns a QuickDraw picture that will draw the
  735.         image stored in the bitmap.  BitMapToPICT is the inverse
  736.         of PICTToBitMap.
  737.  
  738.     example application:
  739.         In this example, we create a bitmap and convert it into a QuickDraw
  740.         picture.
  741.         
  742.         {   PicHandle the_picture;
  743.             BitMap *the_bits;
  744.             
  745.             the_bits = NewBitMap(100, 200);
  746.             if (the_bits != NULL) {
  747.             
  748.                 the_picture = BitMapToPICT(the_bits);
  749.                 
  750.                 KillBitMap(the_bits);
  751.             
  752.             }
  753.             
  754.     notes:
  755.         QuickDraw pictures are a good way to store image data.
  756.  
  757.  
  758. æKY BitMapAND
  759. æFc BitMap.h
  760. æMM
  761. æD BitMap* BitMapAND(BitMap* a, BitMap* b);
  762. æDT BitMap *anded_bits = BitMapAND((BitMap*) a, (BitMap*) b);
  763. æT Function
  764. æC -----
  765. to logically AND the raster data from two bitmaps. 
  766.     
  767.     arguments:
  768.         a        a bitmap pointer
  769.         b        a bitmap pointer
  770.     
  771.     return value:
  772.         a bitmap pointer containing the logical result of ANDing the
  773.         raster data from bitmap a with the raster data from bitmap b. 
  774.         if an error occurs, NULL is returned.
  775.         
  776.     description:
  777.         BitMapAND logically ANDs the raster data of two bitmap pointers
  778.         returning a new bitmap pointer containing the result.  The two
  779.         parameter bitmaps must have identical dimensions.
  780.  
  781.     example application:
  782.         In this example, we create two bitmaps and AND them together creating
  783.         a third bitmap.
  784.         
  785.         {   BitMap *a=NULL, *b=NULL, *c=NULL;
  786.             
  787.             a = NewBitMap(100, 100);
  788.             if (a == NULL) goto my_error_handler;
  789.             b = NewBitMap(100, 100);
  790.             if (b == NULL) goto my_error_handler;
  791.             
  792.             c = BitMapAND(a, b);
  793.             if (c == NULL) goto my_error_handler;
  794.             
  795.                 /* at this point, c contains the result of logically ANDing
  796.                 the bitmaps a and b */
  797.         
  798.         my_error_handler:
  799.             if (a != NULL) KillBitMap(a);
  800.             if (b != NULL) KillBitMap(b);
  801.             if (c != NULL) KillBitMap(c);
  802.         }
  803.         
  804.     notes:
  805.         useful for calculating the intersection of two sets of bits.
  806.  
  807.  
  808. æKY BitMapOR
  809. æFc BitMap.h
  810. æMM
  811. æD BitMap* BitMapOR(BitMap* a, BitMap* b);
  812. æDT BitMap *ored_bits = BitMapOR((BitMap*) a, (BitMap*) b);
  813. æT Function
  814. æC -----
  815. to logically OR the raster data from two bitmaps. 
  816.     
  817.     arguments:
  818.         a        a bitmap pointer
  819.         b        a bitmap pointer
  820.     
  821.     return value:
  822.         a bitmap pointer containing the logical result of ORing the
  823.         raster data from bitmap a with the raster data from bitmap b. 
  824.         if an error occurs, NULL is returned.
  825.         
  826.     description:
  827.         BitMapOR logically ORs the raster data of two bitmap pointers
  828.         returning a new bitmap pointer containing the result.  The two
  829.         parameter bitmaps must have identical dimensions.
  830.  
  831.     example application:
  832.         In this example, we create two bitmaps and OR them together creating
  833.         a third bitmap.
  834.         
  835.         {   BitMap *a=NULL, *b=NULL, *c=NULL;
  836.             
  837.             a = NewBitMap(100, 100);
  838.             if (a == NULL) goto my_error_handler;
  839.             b = NewBitMap(100, 100);
  840.             if (b == NULL) goto my_error_handler;
  841.             
  842.             c = BitMapOR(a, b);
  843.             if (c == NULL) goto my_error_handler;
  844.             
  845.                 /* at this point, c contains the result of logically ORing
  846.                 the bitmaps a and b */
  847.         
  848.         my_error_handler:
  849.             if (a != NULL) KillBitMap(a);
  850.             if (b != NULL) KillBitMap(b);
  851.             if (c != NULL) KillBitMap(c);
  852.         }
  853.         
  854.     notes:
  855.         useful for calculating the union of two sets of bits.
  856.  
  857.  
  858. æKY BitMapXOR
  859. æFc BitMap.h
  860. æMM
  861. æD BitMap* BitMapXOR(BitMap* a, BitMap* b);
  862. æDT BitMap *xored_bits = BitMapXOR((BitMap*) a, (BitMap*) b);
  863. æT Function
  864. æC -----
  865. to logically XOR the raster data from two bitmaps. 
  866.     
  867.     arguments:
  868.         a        a bitmap pointer
  869.         b        a bitmap pointer
  870.     
  871.     return value:
  872.         a bitmap pointer containing the logical result of XORing the
  873.         raster data from bitmap a with the raster data from bitmap b. 
  874.         if an error occurs, NULL is returned.
  875.         
  876.     description:
  877.         BitMapXOR logically XORs the raster data of two bitmap pointers
  878.         returning a new bitmap pointer containing the result.  The two
  879.         parameter bitmaps must have identical dimensions.
  880.  
  881.     example application:
  882.         In this example, we create two bitmaps and XOR them together creating
  883.         a third bitmap.
  884.         
  885.         {   BitMap *a=NULL, *b=NULL, *c=NULL;
  886.             
  887.             a = NewBitMap(100, 100);
  888.             if (a == NULL) goto my_error_handler;
  889.             b = NewBitMap(100, 100);
  890.             if (b == NULL) goto my_error_handler;
  891.             
  892.             c = BitMapXOR(a, b);
  893.             if (c == NULL) goto my_error_handler;
  894.             
  895.                 /* at this point, c contains the result of logically XORing
  896.                 the bitmaps a and b */
  897.         
  898.         my_error_handler:
  899.             if (a != NULL) KillBitMap(a);
  900.             if (b != NULL) KillBitMap(b);
  901.             if (c != NULL) KillBitMap(c);
  902.         }
  903.         
  904.     notes:
  905.         useful for calculating the difference of two sets of bits.
  906.  
  907.  
  908. æKY BitMapNOT
  909. æFc BitMap.h
  910. æMM
  911. æD BitMap* BitMapNOT(BitMap* a);
  912. æDT BitMap *angry_bits = BitMapNOT((BitMap*) a);
  913. æT Function
  914. æC -----
  915. complement a bitmap. 
  916.     
  917.     arguments:
  918.         a        a bitmap pointer
  919.     
  920.     return value:
  921.         a bitmap pointer containing the logical result of complementing the
  922.         raster data from bitmap a. 
  923.         if an error occurs, NULL is returned.
  924.         
  925.     description:
  926.         BitMapNOT returns a new bitmap pointer containing the inverse
  927.         of the raster image contained in the bitmap pointer a.
  928.  
  929.     example application:
  930.         In this example, we create a bitmap and it's complement.
  931.         
  932.         {   BitMap *a=NULL, *b=NULL;
  933.             
  934.             a = NewBitMap(100, 100);
  935.             if (a == NULL) goto my_error_handler;
  936.             
  937.             b = BitMapNOT(a);
  938.             if (b == NULL) goto my_error_handler;
  939.             
  940.                 /* at this point, b contains the compliment of a */
  941.         
  942.         my_error_handler:
  943.             if (a != NULL) KillBitMap(a);
  944.             if (b != NULL) KillBitMap(b);
  945.         }
  946.         
  947.     notes:
  948.         useful for calculating the complement of a set of bits.
  949.  
  950.  
  951. æKY BitMapTest
  952. æFc BitMap.h
  953. æD Boolean BitMapTest(BitMap* bits, short h, short v);
  954. æDT Boolean pixel_value = BitMapTest((BitMap*) bits, (short) h, (short) v);
  955. æT Function
  956. æC -----
  957. test the value of a particular pixel in a bitmap. 
  958.     
  959.     arguments:
  960.         bits     a bitmap pointer
  961.         h        the horizontal position of the pixel to test
  962.         v        the vertical position of the pixel to test
  963.         
  964.     return value:
  965.         true if the pixel is 1, false if the pixel is 0.
  966.         
  967.     description:
  968.         BitMapTest tests the value of the pixel at the location (h,v)
  969.         returning true if the pixel is 1, and false if the pixel
  970.         is zero.
  971.  
  972.     example application:
  973.         In this example, we create a bitmap and test the pixel
  974.         located at (25, 32).
  975.         
  976.         {   BitMap *bits=NULL;
  977.             
  978.             bits = NewBitMap(100, 100);
  979.             if (bits == NULL) goto my_error_handler;
  980.             
  981.             ....
  982.             
  983.             if (BitMapTest(bits, 25, 32)) {
  984.                 /* the pixel is 1 */
  985.             } else {
  986.                 /* the pixel is 0 */
  987.             }
  988.  
  989.         my_error_handler:
  990.             if (bits != NULL) KillBitMap(bits);
  991.         }
  992.  
  993.     notes:
  994.         attempting to test a point outside of the bitmap's bounds
  995.         will produce unpredictable results.
  996.  
  997.  
  998. æKY BitMapSet
  999. æFc BitMap.h
  1000. æD void BitMapSet(BitMap* bits, short h, short v);
  1001. æDT BitMapSet((BitMap*) bits, (short) h, (short) v);
  1002. æT Procedure
  1003. æC -----
  1004. set the value of a particular pixel. 
  1005.     
  1006.     arguments:
  1007.         bits     a bitmap pointer
  1008.         h        the horizontal position of the pixel to set
  1009.         v        the vertical position of the pixel to set
  1010.     
  1011.     return value:
  1012.         none.
  1013.         
  1014.     description:
  1015.         BitMapSet sets the value of the pixel at the location (h,v) to 1.
  1016.  
  1017.     example application:
  1018.         In this example, we create a bitmap and set the pixel
  1019.         located at (25, 32) to the value 1.
  1020.         
  1021.         {   BitMap *bits=NULL;
  1022.             
  1023.             bits = NewBitMap(100, 100);
  1024.             if (bits == NULL) goto my_error_handler;
  1025.             
  1026.             ....
  1027.             
  1028.             BitMapSet(bits, 25, 32);
  1029.  
  1030.         my_error_handler:
  1031.             if (bits != NULL) KillBitMap(bits);
  1032.         }
  1033.  
  1034.     notes:
  1035.         attempting to set a point outside of the bitmap's bounds
  1036.         will produce unpredictable results and may even crash your
  1037.         computer by overwriting something important like the operating
  1038.         system or your program or something like that.
  1039.  
  1040.  
  1041. æKY BitMapClear
  1042. æFc BitMap.h
  1043. æD void BitMapClear(BitMap* bits, short h, short v);
  1044. æDT BitMapClear((BitMap*) bits, (short) h, (short) v);
  1045. æT Procedure
  1046. æC -----
  1047. clear the value of a particular pixel. 
  1048.     
  1049.     arguments:
  1050.         bits     a bitmap pointer
  1051.         h        the horizontal position of the pixel to set
  1052.         v        the vertical position of the pixel to set
  1053.     
  1054.     return value:
  1055.         none.
  1056.         
  1057.     description:
  1058.         BitMapClear clears the value of the pixel at the location (h,v)
  1059.         to 0.
  1060.  
  1061.     example application:
  1062.         In this example, we create a bitmap and set the pixel
  1063.         located at (25, 32) to the value 0.
  1064.         
  1065.         {   BitMap *bits=NULL;
  1066.             
  1067.             bits = NewBitMap(100, 100);
  1068.             if (bits == NULL) goto my_error_handler;
  1069.             
  1070.             ....
  1071.             
  1072.             BitMapClear(bits, 25, 32);
  1073.  
  1074.         my_error_handler:
  1075.             if (bits != NULL) KillBitMap(bits);
  1076.         }
  1077.  
  1078.     notes:
  1079.         attempting to clear a point outside of the bitmap's bounds
  1080.         will produce unpredictable results and may even crash your
  1081.         computer by overwriting something important like the operating
  1082.         system or your program or something like that.
  1083.  
  1084.  
  1085. æKY BitMapToggle
  1086. æFc BitMap.h
  1087. æD Boolean BitMapToggle(BitMap* bits, short h, short v);
  1088. æDT Boolean new_value = BitMapToggle((BitMap*) bits, (short) h, (short) v);
  1089. æT Procedure
  1090. æC -----
  1091. invert the value of a particular pixel returning it's new value. 
  1092.     
  1093.     arguments:
  1094.         bits     a bitmap pointer
  1095.         h        the horizontal position of the pixel to set
  1096.         v        the vertical position of the pixel to set
  1097.     
  1098.     return value:
  1099.         a boolean value indicating the state of the pixel
  1100.         after the toggle operation.  i.e. if the pixel is
  1101.         set to the value 1, true is returned.  If the pixel
  1102.         is set to the value 0, false is returned.
  1103.         
  1104.     description:
  1105.         BitMapToggle inverts the value of the pixel at the location (h,v)
  1106.         returning true if the pixel is set to 1 or false if the pixel
  1107.         is set to 0.
  1108.  
  1109.     example application:
  1110.         In this example, we create a bitmap and invert the pixel
  1111.         located at (25, 32).
  1112.         
  1113.         {   BitMap *bits=NULL;
  1114.             
  1115.             bits = NewBitMap(100, 100);
  1116.             if (bits == NULL) goto my_error_handler;
  1117.             
  1118.             ....
  1119.             
  1120.             BitMapToggle(bits, 25, 32);
  1121.  
  1122.         my_error_handler:
  1123.             if (bits != NULL) KillBitMap(bits);
  1124.         }
  1125.  
  1126.     notes:
  1127.         attempting to toggle a point outside of the bitmap's bounds
  1128.         will produce unpredictable results and may even crash your
  1129.         computer by overwriting something important like the operating
  1130.         system or your program or something like that.
  1131.  
  1132.  
  1133. æKY NewBMP
  1134. æFc BitMap.h
  1135. æMM
  1136. æD BitMapPort* NewBMP(BitMap* bits);
  1137. æDT BitMapPort *bmp = NewBMP((BitMap*) bits);
  1138. æT Function
  1139. æC -----
  1140. set up a drawing environment for drawing into a bitmap. 
  1141.     
  1142.     arguments:
  1143.         bits    a bitmap pointer
  1144.     
  1145.     return value:
  1146.         a pointer to a BitMapPort data structure.
  1147.         if an error occurs, NULL is returned.
  1148.         
  1149.     description:
  1150.         NewBMP is called by the WithBitMap macro and you should
  1151.         never have to call it directly yourself.  What it does is
  1152.         it saves the original grafport, and creates a new grafport
  1153.         suitable for drawing into the bitmap.  NewBMP should be
  1154.         followed by a call to DisposeBMP which will restore the
  1155.         original grafport, unlock the bitmap, and dispose of the
  1156.         new grafport.
  1157.  
  1158.     example application:
  1159.         In this example, we create a bitmap and use the NewBMP to make
  1160.         a grafport.  Then we draw into it and call DisposeBMP to deallocate
  1161.         the grafport.
  1162.         
  1163.         {   BitMap *bits=NULL;
  1164.             BitMapPort *bmp=NULL;
  1165.             
  1166.             bits = NewBitMap(100, 100);
  1167.             if (bits == NULL) goto my_error_handler;
  1168.             bmp = NewBMP(bits);
  1169.             if (bmp == NULL) goto my_error_handler;
  1170.                 
  1171.                 /* after NewBMP, the grafport is set to draw into the bitmap */
  1172.             MoveTo(10,10);
  1173.             LineTo(20,20);
  1174.             DrawString("\pHello World");
  1175.  
  1176.         my_error_handler:
  1177.             if (bmp != NULL) DisposeBMP(bmp);
  1178.             if (bits != NULL) KillBitMap(bits);
  1179.             
  1180.         }
  1181.  
  1182.     notes:
  1183.         if NewBMP returns a pointer to a BitMapPort, then you must
  1184.         dispose of that pointer with a call to DisposeBMP.
  1185.  
  1186.  
  1187. æKY DisposeBMP
  1188. æFc BitMap.h
  1189. æMM
  1190. æD void DisposeBMP(BitMapPort* bmp);
  1191. æDT DisposeBMP((BitMapPort*) bmp);
  1192. æT Procedure
  1193. æC -----
  1194. dispose of a drawing enviroment created by NewBMP and restore the previous
  1195. drawing environment. 
  1196.     
  1197.     arguments:
  1198.         bmp        a pointer to a BitMapPort structure allocated by NewBMP
  1199.     
  1200.     return value:
  1201.         none.
  1202.         
  1203.     description:
  1204.         DisposeBMP restores the original grafport and, deallocates
  1205.         the grafport allocated for drawing into the bitmap.
  1206.         The macro WithBitMap calls this routine automatically and you will
  1207.         not normally have to call it directly.
  1208.  
  1209.     example application:
  1210.         see the example in NewBMP.
  1211.         
  1212.     notes:
  1213.         none.
  1214.  
  1215.  
  1216. æKY WithBitMap
  1217. æFc BitMap.h
  1218. æMM
  1219. æD #define WithBitMap(bits, bmp)
  1220. æDT WithBitMap(((BitMap*) bits), ((BitMapPort*) bmp)) { statement... }
  1221. æT Macro
  1222. æC -----
  1223. execute a statement while the drawing environment is set up to
  1224. draw into the bitmap. 
  1225.     
  1226.     arguments:
  1227.         bits           a bitmap pointer
  1228.         bmp            a variable you have declared of type BitMapPort*
  1229.     
  1230.     return value:
  1231.         not applicable
  1232.         
  1233.     description:
  1234.         WithBitMap is a macro facility that sets up the drawing
  1235.         environment such that any drawing commands in the statement
  1236.         following the macro instantiation will draw into the bitmap
  1237.         provided as the first parameter.
  1238.  
  1239.     example application:
  1240.         In this example, we create a bitmap and use the WithBitMap
  1241.         macro to do some drawing in it.
  1242.         
  1243.         {   BitMap *bits=NULL;
  1244.             BitMapPort *bmp;
  1245.             
  1246.             bits = NewBitMap(100, 100);
  1247.             if (bits == NULL) goto my_error_handler;
  1248.             
  1249.             WithBitMap(bits, bmp) {
  1250.                 MoveTo(10,10);
  1251.                 LineTo(20,20);
  1252.                 TextFont(geneva);
  1253.                 TextSize(12);
  1254.                 DrawString("\pHello World");
  1255.             }
  1256.  
  1257.         my_error_handler:
  1258.             if (bits != NULL) KillBitMap(bits);
  1259.             
  1260.         }
  1261.  
  1262.     notes:
  1263.         WithBitMap macros can be nested, however if you do this you must
  1264.         provide a different variable of type (BitMapPort *) for each
  1265.         instantiation. 
  1266.  
  1267.  
  1268. æKY PlotBitMap
  1269. æFc BitMap.h
  1270. æMM
  1271. æD void PlotBitMap(BitMap* bits, short h, short v);
  1272. æDT PlotBitMap((BitMap*) bits, (short) h, (short) v);
  1273. æT Procedure
  1274. æC -----
  1275. for creating a new bitmap pointer. 
  1276.     
  1277.     arguments:
  1278.         bits        a bitmap pointer
  1279.         h           the horizontal location where the bitmap is drawn
  1280.         v           the horizontal location where the bitmap is drawn
  1281.         mode        transfer mode passed to copybits
  1282.     
  1283.     return value:
  1284.         none.
  1285.         
  1286.     description:
  1287.         PlotBitMap provides a simple interface for drawing a bitmap in
  1288.         the current grafport.  The bitmap is drawn with the top left corner
  1289.         aligned with the point (h,v) using the indicated transfer mode.
  1290.         
  1291.         In this example, we create a bitmap and use the WithBitMap
  1292.         macro to do some drawing in it, and then we copy the result
  1293.         to the current grafport at the location (75, 23) using the
  1294.         PlotBitMap routine.
  1295.         
  1296.         {   BitMap *bits=NULL;
  1297.             BitMapPort *bmp;
  1298.             
  1299.             bits = NewBitMap(100, 100);
  1300.             if (bits == NULL) goto my_error_handler;
  1301.             
  1302.             WithBitMap(bits, bmp) {
  1303.                 MoveTo(10,10);
  1304.                 TextFont(geneva);
  1305.                 TextSize(12);
  1306.                 DrawString("\pHello World");
  1307.             }
  1308.             
  1309.            PlotBitMap(bits, 75, 23, srcCopy);
  1310.  
  1311.         my_error_handler:
  1312.             if (bits != NULL) KillBitMap(bits);
  1313.             
  1314.         }
  1315.  
  1316.     notes:
  1317.         PlotBitMap calls CopyBits.
  1318.  
  1319.  
  1320. æKY BitMapPort
  1321. æFc BitMap.h
  1322. æT structure
  1323. æD typedef struct {
  1324.     GrafPort gp;     /* the grafport record for drawing into the bitmap */
  1325.     GrafPtr gpsave;  /* saved grafport for later restoration */
  1326.     BitMap* bits;   /* the bitmap handle */
  1327. } BitMapPort;
  1328. æC -----
  1329. BitMapPort data structure managed by the routines NewBMP
  1330. and DisposeBMP.  You should never have to access the fields of this
  1331. record directly as it's all taken care of by NewBMP and DisposeBMP.
  1332.  
  1333.  
  1334.  
  1335.